home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk10.zip / FPE_TEST.V7 < prev    next >
Text File  |  1991-10-05  |  2KB  |  87 lines

  1. : tests if mawk has been compiled to correctly handle
  2. : floating point exceptions
  3.  
  4. test1='BEGIN{ print 4/0 }'
  5.  
  6.  
  7. test2='BEGIN { 
  8.   x = 100
  9.   do { y = x ; x *= 1000 } while ( y != x )
  10.   print "loop terminated"
  11. }'
  12.  
  13. test3='BEGIN{ print log(-8) }'
  14.  
  15.  
  16. echo "testing division by zero"
  17. echo mawk "$test1"
  18. ./mawk "$test1"
  19. ret1=$?
  20. echo
  21.  
  22. echo "testing overflow"
  23. echo mawk "$test2"
  24. ./mawk "$test2"
  25. ret2=$?
  26. echo
  27.  
  28. echo "testing domain error"
  29. echo mawk "$test3"
  30. ./mawk "$test3" > temp$$
  31. ret3=$?
  32. cat temp$$
  33. echo
  34.  
  35.  
  36. : the returns should all be zero or all 1
  37. : core dumps not allowed
  38.  
  39. echo
  40. echo ==============================
  41.  
  42. echo return1 = $ret1
  43. echo return2 = $ret2
  44. echo return3 = $ret3
  45.  
  46.  
  47. [ $ret1 -gt 128 ] && { echo test1 failed ; exception=1 ; }
  48. [ $ret2 -gt 128 ] && { echo test2 failed ; exception=1 ; }
  49. [ $ret3 -gt 128 ] && { echo test3 failed ; exception=1 ; }
  50.  
  51. [ "$exception" = 1 ] && { rm -f core temp$$ ; exit 1 ; }
  52.  
  53.  
  54. same=0
  55.  
  56. [ $ret1 = $ret2 ] && [ $ret2 = $ret3 ] && same=1
  57.  
  58.  
  59. if [ $same = 1 ]
  60.    then
  61.    if [ $ret1 = 0 ]
  62.       then 
  63.     echo results consistent: ignoring floating exceptions
  64.     if  grep -i nan temp$$  > /dev/null
  65.        then :
  66.        else
  67.          echo "but the library is not IEEE754 compatible"
  68.          echo "test 3 failed"
  69.          rm temp$$
  70.     fi
  71.       else echo results consistent: trapping floating exceptions
  72.    fi
  73.  
  74.    rm -f temp$$
  75.    exit 0
  76.  
  77.    else
  78.    echo results are not consistent
  79. echo 'return values should all be 0 if ignoring FPEs (i.e. with IEEE754)
  80. or all 1 if trapping FPEs
  81. '
  82.  
  83. rm -f temp$$
  84. exit 1
  85. fi
  86.  
  87.